home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / popeye.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  14KB  |  387 lines

  1. /***************************************************************************
  2.  
  3. Popeye memory map (preliminary)
  4.  
  5. driver by Marc Lafontaine
  6.  
  7. 0000-7fff  ROM
  8.  
  9. 8000-87ff  RAM
  10. 8c00       background x position
  11. 8c01       background y position
  12. 8c02       ?
  13. 8c03       bit 3: background palette bank
  14.            bit 0-2: sprite palette bank
  15. 8c04-8e7f  sprites
  16. 8f00-8fff  RAM (stack)
  17.  
  18. a000-a3ff  Text video ram
  19. a400-a7ff  Text Attribute
  20.  
  21. c000-cfff  Background bitmap. Accessed as nibbles: bit 7 selects which of
  22.            the two nibbles should be written to.
  23.  
  24.  
  25. I/O 0  ;AY-3-8910 Control Reg.
  26. I/O 1  ;AY-3-8910 Data Write Reg.
  27.         write to port B: select bit of DSW2 to read in bit 7 of port A (0-2-4-6-8-a-c-e)
  28. I/O 3  ;AY-3-8910 Data Read Reg.
  29.         read from port A: bit 0-5 = DSW1  bit 7 = bit of DSW1 selected by port B
  30.  
  31.         DSW1
  32.         bit 0-3 = coins per play (0 = free play)
  33.         bit 4-5 = ?
  34.  
  35.         DSW2
  36.         bit 0-1 = lives
  37.         bit 2-3 = difficulty
  38.         bit 4-5 = bonus
  39.         bit 6 = demo sounds
  40.         bit 7 = cocktail/upright (0 = upright)
  41.  
  42. I/O 2  ;bit 0 Coin in 1
  43.         bit 1 Coin in 2
  44.         bit 2 Coin in 3 = 5 credits
  45.         bit 3
  46.         bit 4 Start 2 player game
  47.         bit 5 Start 1 player game
  48.         bit 6
  49.         bit 7
  50.  
  51. ***************************************************************************/
  52.  
  53. #include "driver.h"
  54. #include "vidhrdw/generic.h"
  55.  
  56.  
  57.  
  58. extern unsigned char *popeye_videoram;
  59. extern size_t popeye_videoram_size;
  60. extern unsigned char *popeye_background_pos,*popeye_palette_bank;
  61. WRITE_HANDLER( popeye_backgroundram_w );
  62. WRITE_HANDLER( popeye_videoram_w );
  63. WRITE_HANDLER( popeye_colorram_w );
  64. WRITE_HANDLER( popeye_palettebank_w );
  65. void popeye_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
  66. void popeyebl_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
  67. void popeye_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  68. int  popeye_vh_start(void);
  69. void popeye_vh_stop(void);
  70.  
  71.  
  72.  
  73. static struct MemoryReadAddress readmem[] =
  74. {
  75.     { 0x0000, 0x7fff, MRA_ROM },
  76.     { 0x8000, 0x87ff, MRA_RAM },
  77.     { 0x8c00, 0x8e7f, MRA_RAM },
  78.     { 0x8f00, 0x8fff, MRA_RAM },
  79.     { -1 }    /* end of table */
  80. };
  81.  
  82. static struct MemoryWriteAddress writemem[] =
  83. {
  84.     { 0x0000, 0x7fff, MWA_ROM },
  85.     { 0x8000, 0x87ff, MWA_RAM },
  86.     { 0x8c04, 0x8e7f, MWA_RAM, &spriteram, &spriteram_size },
  87.     { 0x8f00, 0x8fff, MWA_RAM },
  88.     { 0xa000, 0xa3ff, videoram_w, &videoram, &videoram_size },
  89.     { 0xa400, 0xa7ff, colorram_w, &colorram },
  90.     { 0xc000, 0xcfff, popeye_videoram_w, &popeye_videoram, &popeye_videoram_size },
  91.     { 0x8c00, 0x8c01, MWA_RAM, &popeye_background_pos },
  92.     { 0x8c03, 0x8c03, popeye_palettebank_w, &popeye_palette_bank },
  93.     { -1 }    /* end of table */
  94. };
  95.  
  96.  
  97.  
  98. static struct IOReadPort readport[] =
  99. {
  100.     { 0x00, 0x00, input_port_0_r },
  101.     { 0x01, 0x01, input_port_1_r },
  102.     { 0x02, 0x02, input_port_2_r },
  103.     { 0x03, 0x03, AY8910_read_port_0_r },
  104.     { -1 }    /* end of table */
  105. };
  106.  
  107. static struct IOWritePort writeport[] =
  108. {
  109.     { 0x00, 0x00, AY8910_control_port_0_w },
  110.     { 0x01, 0x01, AY8910_write_port_0_w },
  111.     { -1 }    /* end of table */
  112. };
  113.  
  114.  
  115. INPUT_PORTS_START( popeye )
  116.  
  117.     PORT_START    /* IN0 */
  118.     PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT | IPF_4WAY )
  119.     PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT | IPF_4WAY )
  120.     PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP | IPF_4WAY )
  121.     PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN | IPF_4WAY )
  122.     PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 )
  123.     PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  124.     PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  125.     PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  126.  
  127.     PORT_START    /* IN1 */
  128.     PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT | IPF_4WAY | IPF_COCKTAIL )
  129.     PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT | IPF_4WAY | IPF_COCKTAIL )
  130.     PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP | IPF_4WAY | IPF_COCKTAIL )
  131.     PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN | IPF_4WAY | IPF_COCKTAIL )
  132.     PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 | IPF_COCKTAIL )
  133.     PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  134.     PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  135.     PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  136.  
  137.     PORT_START    /* IN2 */
  138.     PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  139.     PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  140.     PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_START1 )
  141.     PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START2 )
  142.     PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* probably unused */
  143.     PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_COIN3 )
  144.     PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_COIN2 )
  145.     PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_COIN1 )
  146.  
  147.     PORT_START    /* DSW0 */
  148.     PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coinage ) )
  149.     PORT_DIPSETTING(    0x03, DEF_STR( 3C_1C ) )
  150.     PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
  151.     PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ) )
  152.     PORT_DIPSETTING(    0x06, DEF_STR( 1C_2C ) )
  153.     PORT_DIPSETTING(    0x02, DEF_STR( 2C_5C ) )
  154.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_3C ) )
  155.     PORT_DIPSETTING(    0x09, DEF_STR( 1C_4C ) )
  156.     PORT_DIPSETTING(    0x05, DEF_STR( 1C_5C ) )
  157.     PORT_DIPSETTING(    0x08, DEF_STR( 1C_6C ) )
  158.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  159. /*  0x0e = 2 Coins/1 Credit
  160.     0x07, 0x0c = 1 Coin/1 Credit
  161.     0x01, 0x0b, 0x0d = 1 Coin/2 Credits */
  162.     PORT_BIT( 0xf0, IP_ACTIVE_HIGH, IPT_UNUSED )    /* bit 7 scans DSW1 one bit at a time */
  163.  
  164.     PORT_START    /* DSW1 (FAKE - appears as bit 7 of DSW0, see code below) */
  165.     PORT_DIPNAME( 0x03, 0x01, DEF_STR( Lives ) )
  166.     PORT_DIPSETTING(    0x03, "1" )
  167.     PORT_DIPSETTING(    0x02, "2" )
  168.     PORT_DIPSETTING(    0x01, "3" )
  169.     PORT_DIPSETTING(    0x00, "4" )
  170.     PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Difficulty ) )
  171.     PORT_DIPSETTING(    0x0c, "Easy" )
  172.     PORT_DIPSETTING(    0x08, "Medium" )
  173.     PORT_DIPSETTING(    0x04, "Hard" )
  174.     PORT_DIPSETTING(    0x00, "Hardest" )
  175.     PORT_DIPNAME( 0x30, 0x30, DEF_STR( Bonus_Life ) )
  176.     PORT_DIPSETTING(    0x30, "40000" )
  177.     PORT_DIPSETTING(    0x20, "60000" )
  178.     PORT_DIPSETTING(    0x10, "80000" )
  179.     PORT_DIPSETTING(    0x00, "None" )
  180.     PORT_DIPNAME( 0x40, 0x00, DEF_STR( Demo_Sounds ) )
  181.     PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
  182.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  183.     PORT_DIPNAME( 0x80, 0x00, DEF_STR( Cabinet ) )
  184.     PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
  185.     PORT_DIPSETTING(    0x80, DEF_STR( Cocktail ) )
  186. INPUT_PORTS_END
  187.  
  188.  
  189. static struct GfxLayout charlayout =
  190. {
  191.     16,16,    /* 16*16 characters (8*8 doubled) */
  192.     256,    /* 256 characters */
  193.     1,    /* 1 bit per pixel (there are two bitplanes in the ROM, but only one is used) */
  194.     { 0 },
  195.     { 7,7, 6,6, 5,5, 4,4, 3,3, 2,2, 1,1, 0,0 },    /* pretty straightforward layout */
  196.     { 0*8,0*8, 1*8,1*8, 2*8,2*8, 3*8,3*8, 4*8,4*8, 5*8,5*8, 6*8,6*8, 7*8,7*8 },
  197.     8*8    /* every char takes 8 consecutive bytes */
  198. };
  199. static struct GfxLayout spritelayout =
  200. {
  201.     16,16,    /* 16*16 sprites */
  202.     512,    /* 512 sprites */
  203.     2,    /* 2 bits per pixel */
  204.     { 0, 0x4000*8 },    /* the two bitplanes are separated in different files */
  205.     {7+(0x2000*8),6+(0x2000*8),5+(0x2000*8),4+(0x2000*8),
  206.      3+(0x2000*8),2+(0x2000*8),1+(0x2000*8),0+(0x2000*8),
  207.    7,6,5,4,3,2,1,0 },
  208.     { 15*8, 14*8, 13*8, 12*8, 11*8, 10*8, 9*8, 8*8,
  209.     7*8, 6*8, 5*8, 4*8, 3*8, 2*8, 1*8, 0*8, },
  210.     16*8    /* every sprite takes 16 consecutive bytes */
  211. };
  212.  
  213.  
  214.  
  215. static struct GfxDecodeInfo gfxdecodeinfo[] =
  216. {
  217.     { REGION_GFX1, 0x0000, &charlayout,      0, 16 },    /* chars */
  218.     { REGION_GFX2, 0x0000, &spritelayout, 16*2, 64 },    /* sprites */
  219.     { -1 } /* end of array */
  220. };
  221.  
  222.  
  223.  
  224. static int dswbit;
  225.  
  226. static WRITE_HANDLER( popeye_portB_w )
  227. {
  228.     /* bit 0 does something - RV in the schematics */
  229.  
  230.     /* bits 1-3 select DSW1 bit to read */
  231.     dswbit = (data & 0x0e) >> 1;
  232. }
  233.  
  234. static READ_HANDLER( popeye_portA_r )
  235. {
  236.     int res;
  237.  
  238.  
  239.     res = input_port_3_r(offset);
  240.     res |= (input_port_4_r(offset) << (7-dswbit)) & 0x80;
  241.  
  242.     return res;
  243. }
  244.  
  245. static struct AY8910interface ay8910_interface =
  246. {
  247.     1,    /* 1 chip */
  248.     2000000,    /* 2 MHz */
  249.     { 40 },
  250.     { popeye_portA_r },
  251.     { 0 },
  252.     { 0 },
  253.     { popeye_portB_w }
  254. };
  255.  
  256.  
  257.  
  258. static struct MachineDriver machine_driver_popeyebl =
  259. {
  260.     /* basic machine hardware */
  261.     {
  262.         {
  263.             CPU_Z80,
  264.             4000000,    /* 4 Mhz */
  265.             readmem,writemem,readport,writeport,
  266.             nmi_interrupt,2
  267.         }
  268.     },
  269.     30, DEFAULT_30HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  270.     1,    /* single CPU, no need for interleaving */
  271.     0,
  272.  
  273.     /* video hardware */
  274.     32*16, 30*16, { 0*16, 32*16-1, 1*16, 29*16-1 },
  275.     gfxdecodeinfo,
  276.     32+16+256, 16*2+64*4,
  277.     popeyebl_vh_convert_color_prom,
  278.  
  279.     VIDEO_TYPE_RASTER | VIDEO_SUPPORTS_DIRTY,
  280.     0,
  281.     popeye_vh_start,
  282.     popeye_vh_stop,
  283.     popeye_vh_screenrefresh,
  284.  
  285.     /* sound hardware */
  286.     0,0,0,0,
  287.     {
  288.         {
  289.             SOUND_AY8910,
  290.             &ay8910_interface
  291.         }
  292.     }
  293. };
  294.  
  295.  
  296.  
  297. /***************************************************************************
  298.  
  299.   Game driver(s)
  300.  
  301. ***************************************************************************/
  302.  
  303. ROM_START( popeye )
  304.     ROM_REGION( 0x10000, REGION_CPU1 )    /* 64k for code */
  305.     ROM_LOAD( "c-7a",         0x0000, 0x2000, 0x9af7c821 )
  306.     ROM_LOAD( "c-7b",         0x2000, 0x2000, 0xc3704958 )
  307.     ROM_LOAD( "c-7c",         0x4000, 0x2000, 0x5882ebf9 )
  308.     ROM_LOAD( "c-7e",         0x6000, 0x2000, 0xef8649ca )
  309.  
  310.     ROM_REGION( 0x0800, REGION_GFX1 | REGIONFLAG_DISPOSE )
  311.     ROM_LOAD( "v-5n",         0x0000, 0x0800, 0xcca61ddd )    /* first half is empty */
  312.     ROM_CONTINUE(             0x0000, 0x0800 )
  313.  
  314.     ROM_REGION( 0x8000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  315.     ROM_LOAD( "v-1e",         0x0000, 0x2000, 0x0f2cd853 )
  316.     ROM_LOAD( "v-1f",         0x2000, 0x2000, 0x888f3474 )
  317.     ROM_LOAD( "v-1j",         0x4000, 0x2000, 0x7e864668 )
  318.     ROM_LOAD( "v-1k",         0x6000, 0x2000, 0x49e1d170 )
  319.  
  320.     ROM_REGION( 0x0340, REGION_PROMS )
  321.     ROM_LOAD( "prom-cpu.4a",  0x0000, 0x0020, 0x375e1602 ) /* background palette */
  322.     ROM_LOAD( "prom-cpu.3a",  0x0020, 0x0020, 0xe950bea1 ) /* char palette */
  323.     ROM_LOAD( "prom-cpu.5b",  0x0040, 0x0100, 0xc5826883 ) /* sprite palette - low 4 bits */
  324.     ROM_LOAD( "prom-cpu.5a",  0x0140, 0x0100, 0xc576afba ) /* sprite palette - high 4 bits */
  325.     ROM_LOAD( "prom-vid.7j",  0x0240, 0x0100, 0xa4655e2e ) /* timing for the protection ALU */
  326. ROM_END
  327.  
  328. ROM_START( popeye2 )
  329.     ROM_REGION( 0x10000, REGION_CPU1 )    /* 64k for code */
  330.     ROM_LOAD( "7a",           0x0000, 0x2000, 0x0bd04389 )
  331.     ROM_LOAD( "7b",           0x2000, 0x2000, 0xefdf02c3 )
  332.     ROM_LOAD( "7c",           0x4000, 0x2000, 0x8eee859e )
  333.     ROM_LOAD( "7e",           0x6000, 0x2000, 0xb64aa314 )
  334.  
  335.     ROM_REGION( 0x0800, REGION_GFX1 | REGIONFLAG_DISPOSE )
  336.     ROM_LOAD( "v-5n",         0x0000, 0x0800, 0xcca61ddd )    /* first half is empty */
  337.     ROM_CONTINUE(             0x0000, 0x0800 )
  338.  
  339.     ROM_REGION( 0x8000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  340.     ROM_LOAD( "v-1e",         0x0000, 0x2000, 0x0f2cd853 )
  341.     ROM_LOAD( "v-1f",         0x2000, 0x2000, 0x888f3474 )
  342.     ROM_LOAD( "v-1j",         0x4000, 0x2000, 0x7e864668 )
  343.     ROM_LOAD( "v-1k",         0x6000, 0x2000, 0x49e1d170 )
  344.  
  345.     ROM_REGION( 0x0340, REGION_PROMS )
  346.     ROM_LOAD( "prom-cpu.4a",  0x0000, 0x0020, 0x375e1602 ) /* background palette */
  347.     ROM_LOAD( "prom-cpu.3a",  0x0020, 0x0020, 0xe950bea1 ) /* char palette */
  348.     ROM_LOAD( "prom-cpu.5b",  0x0040, 0x0100, 0xc5826883 ) /* sprite palette - low 4 bits */
  349.     ROM_LOAD( "prom-cpu.5a",  0x0140, 0x0100, 0xc576afba ) /* sprite palette - high 4 bits */
  350.     ROM_LOAD( "prom-vid.7j",  0x0240, 0x0100, 0xa4655e2e ) /* timing for the protection ALU */
  351. ROM_END
  352.  
  353. ROM_START( popeyebl )
  354.     ROM_REGION( 0x10000, REGION_CPU1 )    /* 64k for code */
  355.     ROM_LOAD( "po1",          0x0000, 0x2000, 0xb14a07ca )
  356.     ROM_LOAD( "po2",          0x2000, 0x2000, 0x995475ff )
  357.     ROM_LOAD( "po3",          0x4000, 0x2000, 0x99d6a04a )
  358.     ROM_LOAD( "po4",          0x6000, 0x2000, 0x548a6514 )
  359.     ROM_LOAD( "po_d1-e1.bin", 0xe000, 0x0020, 0x8de22998 )    /* protection PROM */
  360.  
  361.     ROM_REGION( 0x0800, REGION_GFX1 | REGIONFLAG_DISPOSE )
  362.     ROM_LOAD( "v-5n",         0x0000, 0x0800, 0xcca61ddd )    /* first half is empty */
  363.     ROM_CONTINUE(             0x0000, 0x0800 )
  364.  
  365.     ROM_REGION( 0x8000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  366.     ROM_LOAD( "v-1e",         0x0000, 0x2000, 0x0f2cd853 )
  367.     ROM_LOAD( "v-1f",         0x2000, 0x2000, 0x888f3474 )
  368.     ROM_LOAD( "v-1j",         0x4000, 0x2000, 0x7e864668 )
  369.     ROM_LOAD( "v-1k",         0x6000, 0x2000, 0x49e1d170 )
  370.  
  371.     ROM_REGION( 0x0240, REGION_PROMS )
  372.     ROM_LOAD( "popeye.pr1",   0x0000, 0x0020, 0xd138e8a4 ) /* background palette */
  373.     ROM_LOAD( "popeye.pr2",   0x0020, 0x0020, 0x0f364007 ) /* char palette */
  374.     ROM_LOAD( "popeye.pr3",   0x0040, 0x0100, 0xca4d7b6a ) /* sprite palette - low 4 bits */
  375.     ROM_LOAD( "popeye.pr4",   0x0140, 0x0100, 0xcab9bc53 ) /* sprite palette - high 4 bits */
  376. ROM_END
  377.  
  378.  
  379.  
  380. /* The original doesn't work because the ROMs are encrypted. */
  381. /* The encryption is based on a custom ALU and seems to be dynamically evolving */
  382. /* (like Jr. PacMan). I think it decodes 16 bits at a time, bits 0-2 are (or can be) */
  383. /* an opcode for the ALU and the others contain the data. */
  384. GAMEX( 1982?, popeye,   0,      popeyebl, popeye, 0, ROT0, "Nintendo", "Popeye (set 1)", GAME_NOT_WORKING | GAME_NO_COCKTAIL )
  385. GAMEX( 1982?, popeye2,  popeye, popeyebl, popeye, 0, ROT0, "Nintendo", "Popeye (set 2)", GAME_NOT_WORKING | GAME_NO_COCKTAIL )
  386. GAMEX( 1982?, popeyebl, popeye, popeyebl, popeye, 0, ROT0, "bootleg", "Popeye (bootleg)", GAME_NO_COCKTAIL )
  387.